<?PHP

	include("../../includes/configAjax.php");
	include("../../includes/forum/topic.class.php");
	$topic = new topic();
		
		switch($_GET['type']){
			case 'lock':
				if(is_numeric($_GET['topic'])){
					$topid_id = $db->prep($_GET['topic']);
					$outcome = $topic->lockTopic($db, $users, $topid_id);
					if($outcome){
						echo "ok";
					} else {
						echo $lang['error_perms'];	
					}
				} else {
					echo $lang['error_bad_topic'];	
				}
			break;
			case 'unlock':
				if(is_numeric($_GET['topic'])){
					$topid_id = $db->prep($_GET['topic']);
					$outcome = $topic->unlockTopic($db, $users, $topid_id);
					if($outcome){
						echo "ok";
					} else {
						echo $lang['error_perms'];	
					}
				} else {
					echo $lang['error_bad_topic'];	
				}
			break;
			case 'delete':
				if(is_numeric($_GET['topic'])){
					$topid_id = $_GET['topic'];
					$outcome = $topic->deleteTopic($db, $users, $topid_id);
					if($outcome){
						echo "ok";
					} else {
						echo $lang['error_perms'];	
					}
				} else {
					echo $lang['error_bad_topic'];	
				}
			break;
			case 'undelete':
				if(is_numeric($_GET['topic'])){
					$topid_id = $db->prep($_GET['topic']);
					$outcome = $topic->undeleteTopic($db, $users, $topid_id);
					if($outcome){
						echo "ok";
					} else {
						echo $lang['error_perms'];	
					}
				} else {
					echo $lang['error_bad_topic'];	
				}
			break;
			case 'deletePost':
				if(is_numeric($_GET['topicid']) && is_numeric($_GET['postid'])){
					include("../../includes/forum/post.class.php");
					$post = new post();
					
					$topicId = $_GET['topicid'];
					$postId = $_GET['postid'];
					$firstPost = $topic->getOriginalPost($db, $topicId);
					if(mysql_num_rows($firstPost)==1){
						while($row = mysql_fetch_object($firstPost)){
							if($postId==$row->post_id){
								echo $lang['error_bad_delete_original'];	
							} else {
								$outcome = $post->deletePost($db, $users, $postId);	
								if(!$outcome){
									echo $lang['error_bad_delete_misc'];
								} else {
									echo "ok";
								}
							}
						}
					} else {
						echo $lang['error_perms'];	
					}
				} else {
					echo $lang['error_bad_topic'];	
				}
			break;
			case 'undeletePost':
				if(is_numeric($_GET['topicid']) && is_numeric($_GET['postid'])){
					include("../../includes/forum/post.class.php");
					$post = new post();
					
					$topicId = $_GET['topicid'];
					$postId = $_GET['postid'];
					$firstPost = $topic->getOriginalPost($db, $topicId);
					if(mysql_num_rows($firstPost)==1){
						while($row = mysql_fetch_object($firstPost)){
							if($postId==$row->post_id){
								echo $lang['error_bad_undelete_original'];	
							} else {
								$outcome = $post->undeletePost($db, $users, $postId);	
								if(!$outcome){
									echo $lang['error_bad_undelete_misc'];
								} else {
									echo "ok";
								}
							}
						}
					} else {
						echo $lang['error_perms'];	
					}
				} else {
					echo $lang['error_bad_topic'];	
				}
			break;
			case 'stick':
				if(is_numeric($_GET['topicid'])){
					$topic_id = $_GET['topicid'];
					$outcome = $topic->stickTopic($db, $users, $topic_id);
					if($outcome){
						echo "ok";
					} else {
						echo $lang['error_perms'];	 	
					}
				} else {
					echo $lang['error_bad_topic'];	
				}
			break;
			case 'unstick':
				if(is_numeric($_GET['topicid'])){
					$topic_id = $_GET['topicid'];
					$outcome = $topic->unstickTopic($db, $users, $topic_id);
					if($outcome){
						echo "ok";
					} else {
						echo $lang['error_perms'];	 	
					}
				} else {
					echo $lang['error_bad_topic'];	
				}
			break;
		}

?>